<html>
<head><meta charset="utf-8"><title>Cross-compilation and linkers · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html">Cross-compilation and linkers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236018221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236018221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236018221">(Apr 24 2021 at 23:38)</a>:</h4>
<p>I think I'm missing something important about how cross-compilation is supposed to work.</p>
<p>I tried <code>cargo build --release --target aarch64-unknown-linux-musl</code> on a crate I'm working on. After fixing a couple of issues in dependencies, it got most of the way through building, but then at the final link step, it tried to use <code>cc</code> to link. I realize I can fix that by manually defining a linker, but shouldn't cargo be able to figure that out itself?</p>



<a name="236018237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236018237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236018237">(Apr 24 2021 at 23:38)</a>:</h4>
<p>If I copy-paste the (very long) link line and change <code>cc</code> to <code>aarch64-linux-musl-gcc</code>, it links just fine.</p>



<a name="236018293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236018293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236018293">(Apr 24 2021 at 23:39)</a>:</h4>
<p>I'm also trying to figure out whether cargo or rustc is doing the final link step.</p>



<a name="236019478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236019478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236019478">(Apr 24 2021 at 23:55)</a>:</h4>
<p>rustc is the one that invokes the linker</p>



<a name="236019482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236019482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236019482">(Apr 24 2021 at 23:55)</a>:</h4>
<p>and rustc has always defaulted to <code>cc</code> if nothing is otherewise specified</p>



<a name="236019526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236019526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236019526">(Apr 24 2021 at 23:56)</a>:</h4>
<p>all the logic in the <code>cc</code> crate is not mirrored into the compiler itself</p>



<a name="236020153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236020153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236020153">(Apr 25 2021 at 00:04)</a>:</h4>
<p>ya, it is up to the user to specify the target-specific linkers in <code>.cargo/config.toml</code></p>



<a name="236031188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236031188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236031188">(Apr 25 2021 at 02:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116015">Alex Crichton</span> <a href="#narrow/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers/near/236019482">said</a>:</p>
<blockquote>
<p>and rustc has always defaulted to <code>cc</code> if nothing is otherewise specified</p>
</blockquote>
<p>Ah, got it.</p>



<a name="236031212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236031212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236031212">(Apr 25 2021 at 02:47)</a>:</h4>
<p>Is that the <em>desired</em> behavior, or would it potentially be feasible for rustc to gain some more automatic linker handling?</p>



<a name="236036813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236036813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236036813">(Apr 25 2021 at 04:35)</a>:</h4>
<p>afaik it's just been what's always there, but it basically never works if --target is different than --host so I think there's room for improvement</p>



<a name="236037188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Cross-compilation%20and%20linkers/near/236037188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Cross-compilation.20and.20linkers.html#236037188">(Apr 25 2021 at 04:42)</a>:</h4>
<p>I may file a compiler MCP suggesting a change in that area, then, and see what people think.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>